Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.leveltype = undefined;
var $2ccUtil = require("ccUtil");
var $2BaseConfigContainer = require("BaseConfigContainer");
var $2ConstValue = require("ConstValue");
var $2GameUser = require("GameUser");
var $2ServerConfig = require("ServerConfig");
var l;
(function (e) {
  e[e["最新关卡"] = 0] = "最新关卡";
  e[e["热门推荐"] = 1] = "热门推荐";
  e[e["古画找茬"] = 2] = "古画找茬";
  e[e["找梗系列"] = 3] = "找梗系列";
  e[e["消除玩法"] = 4] = "消除玩法";
  e[e["连线配对"] = 5] = "连线配对";
  e[e["音乐文字"] = 6] = "音乐文字";
  e[e["乐趣找字"] = 7] = "乐趣找字";
  e[e["汉字魔法"] = 8] = "汉字魔法";
  e[e["未解锁"] = 9] = "未解锁";
  e[e.end = 10] = "end";
})(l = exports.leveltype || (exports.leveltype = {}));
exports.default = /* */function (_i$BaseConfigContaine) {
  function _class30(e, t, n) {
    var _this185;
    babel_classCallCheck(this, _class30);
    _this185 = _callSuper(this, _class30);
    _this185._datatype = [];
    _this185._types = new Map();
    _this185.loadconfigr(e, t, n);
    return _this185;
  }
  babel_inherits(_class30, _i$BaseConfigContaine);
  return babel_createClass(_class30, [{
    key: "loadconfigr",
    value: function loadconfigr(e, t, n) {
      var _this186 = this;
      var o = this;
      cc.loader.loadRes($2ConstValue.ConstValue.CONFIG_FILE_DIR + "levelconfig", function (i, s) {
        if (i) {
          cc.log("load levelconfig.txt err");
          cc.log(i);
          setTimeout(function () {
            o.loadconfigr(e, t, n);
          }, 1e3);
        } else {
          _this186._datatype = s.json;
          for (var _e103 = 0; _e103 < _this186._datatype.length; _e103++) {
            null != _this186._datatype[_e103] && null == _this186._datatype[_e103].levelsBundleName && (_this186._datatype[_e103].levelsBundleName = "levels");
          }
          e && e.call(t, n);
        }
      });
    }
  }, {
    key: "getlevelById",
    value: function getlevelById(e) {
      return this._datatype[e];
    }
  }, {
    key: "getlevelByName",
    value: function getlevelByName(e) {
      for (var _t89 = 0; _t89 < this._datatype.length; _t89++) {
        if (this._datatype[_t89].prefabName == e) {
          return this._datatype[_t89];
        }
      }
    }
  }, {
    key: "banlevellist",
    value: function banlevellist(e) {
      for (var _t90 = 0; _t90 < this._datatype.length; _t90++) {
        if (-1 != e.indexOf(this._datatype[_t90].prefabName)) {
          this._datatype.splice(_t90, 1);
          _t90--;
        }
      }
    }
  }, {
    key: "getlevelsByType",
    value: function getlevelsByType(e) {
      if (!this._types.has(e)) {
        var _t91 = [];
        for (var _n91 = this._datatype.length - 1; _n91 >= 0; _n91--) {
          this._datatype[_n91].type && -1 != this._datatype[_n91].type.indexOf(e) && _t91.push(this._datatype[_n91]);
        }
        this._types.set(e, _t91);
      }
      return babel_toConsumableArray(this._types.get(e));
    }
  }, {
    key: "getNextByTypeandName",
    value: function getNextByTypeandName(e, t) {
      var n = this.getlevelsByType(e);
      for (var _o162 = 0; _o162 < n.length; _o162++) {
        if (n[_o162].prefabName == t) {
          if (n[_o162 + 1]) {
            return n[_o162 + 1].prefabName;
          } else {
            return null;
          }
        }
      }
    }
  }, {
    key: "getlevelsNewLevels",
    value: function getlevelsNewLevels(e) {
      var t = [];
      for (var _n92 = this._datatype.length - 1; _n92 >= 0; _n92--) {
        t.push(this._datatype[_n92]);
        if (t.length >= e) {
          return t;
        }
      }
      return t;
    }
  }, {
    key: "getlevels",
    value: function getlevels() {
      return this._datatype;
    }
  }, {
    key: "getTuiJianLevel",
    value: function getTuiJianLevel() {
      if (!$2ServerConfig.default.getInstance().gameconfig.config.levelTiyan) {
        return "";
      }
      this.getOrderLevel("古画找茬");
      var e = $2ServerConfig.default.getInstance().gameconfig.config.tuijian;
      var t = [];
      for (var _n93 = 0; _n93 < e.length; _n93++) {
        null != this.getlevelByName(e[_n93]) && ($2GameUser.default.getInstance().getcomplete(e[_n93]) || (t[t.length] = e[_n93]));
      }
      if (t.length > 0) {
        return t[$2ccUtil.default.random(0, t.length - 1)];
      } else {
        return "";
      }
    }
  }, {
    key: "getOrderLevel",
    value: function getOrderLevel(e) {
      var t = $2ServerConfig.default.getInstance().gameconfig.config.banlist;
      this.banlevellist(t);
      var n = this.getlevelsByType(e);
      return this.orderLevels(n);
    }
  }, {
    key: "getLevelByType",
    value: function getLevelByType(e, t, n) {
      var o = $2ServerConfig.default.getInstance().gameconfig.config.banlist;
      this.banlevellist(o);
      var i = this.getlevelsByType(e);
      i = this.orderLevels2(i, t, n);
      return this.orderLevels2(i, t, n);
    }
  }, {
    key: "getLevelsByLevelsType",
    value: function getLevelsByLevelsType(e) {
      var t = $2GameUser.default.getInstance().LevelsType;
      var n = $2ServerConfig.default.getInstance().gameconfig.config.sceneClist;
      var o = $2ServerConfig.default.getInstance().gameconfig.config.sceneDlist;
      switch (t) {
        case 0:
          return this.getOrderLevel(e);
        case 1:
          return this.getLevelByType(e, n, t);
        case 2:
          return this.getLevelByType(e, o, t);
      }
    }
  }, {
    key: "getNextLevel",
    value: function getNextLevel(e, t) {
      for (var _n94 = 0; _n94 < t.length; _n94++) {
        if (t[_n94].prefabName == e) {
          if (t[_n94 + 1]) {
            return t[_n94 + 1].prefabName;
          } else {
            return null;
          }
        }
      }
    }
  }, {
    key: "getNextByOrderTypeandName",
    value: function getNextByOrderTypeandName(e, t) {
      var n = this.getLevelsByLevelsType(e);
      for (var _o163 = 0; _o163 < n.length; _o163++) {
        if (n[_o163].prefabName == t) {
          if (n[_o163 + 1]) {
            return n[_o163 + 1].prefabName;
          } else {
            return null;
          }
        }
      }
    }
  }, {
    key: "orderLevels2",
    value: function orderLevels2(e, t, n) {
      var o = [];
      for (var _s19 = 0; _s19 < t.length; _s19++) {
        for (var _n95 = 0; _n95 < e.length; _n95++) {
          if (null != e[_n95] && t[_s19] == e[_n95].prefabName) {
            o[o.length] = e[_n95];
            e[_n95] = null;
          }
        }
      }
      var i = $2GameUser.default.getInstance().levelOtherPaiXu;
      i[n] = o;
      $2GameUser.default.getInstance().levelOtherPaiXu = i;
      return o;
    }
  }, {
    key: "getFirstPrefab",
    value: function getFirstPrefab(e) {
      return this.getLevelsByLevelsType(e)[0].prefabName;
    }
  }, {
    key: "orderLevels",
    value: function orderLevels(e) {
      var t = $2ServerConfig.default.getInstance().gameconfig.config.sceneAlist;
      var n = $2ServerConfig.default.getInstance().gameconfig.config.sceneBlist;
      var i = [];
      0 == $2GameUser.default.getInstance().gameAB && ($2GameUser.default.getInstance().gameAB = $2ccUtil.default.random(1, 2));
      if (1 == $2GameUser.default.getInstance().gameAB) {
        for (var _n96 = 0; _n96 < t.length; _n96++) {
          for (var _o164 = 0; _o164 < e.length; _o164++) {
            if (null != e[_o164] && t[_n96] == e[_o164].prefabName) {
              i[i.length] = e[_o164];
              e[_o164] = null;
            }
          }
        }
        for (var _t92 = 0; _t92 < e.length; _t92++) {
          null != e[_t92] && (i[i.length] = e[_t92]);
        }
      } else {
        for (var _t93 = 0; _t93 < n.length; _t93++) {
          for (var _o165 = 0; _o165 < e.length; _o165++) {
            if (null != e[_o165] && n[_t93] == e[_o165].prefabName) {
              i[i.length] = e[_o165];
              e[_o165] = null;
            }
          }
        }
        for (var _t94 = 0; _t94 < e.length; _t94++) {
          null != e[_t94] && (i[i.length] = e[_t94]);
        }
      }
      return i;
    }
  }, {
    key: "getFindLevelPrefabName",
    value: function getFindLevelPrefabName(e, t) {
      var n = [];
      for (var _o166 = 0; _o166 < e.length; _o166++) {
        for (var _t95 = 0; _t95 < this._datatype.length; _t95++) {
          this._datatype[_t95].prefabName == e[_o166] && n.push(this._datatype[_t95]);
        }
      }
      if (t == l.最新关卡) {
        if (n.length < 62) {
          for (var _o167 = this._datatype.length - 1; _o167 >= 0; _o167--) {
            if (n.indexOf(this._datatype[_o167]) < 0 && (n.push(this._datatype[_o167]), n.length >= 62)) {
              return n;
            }
          }
        }
      } else if (t == l.热门推荐 || t == l.古画找茬 || t == l.乐趣找字) {
        for (var _o168 = this._datatype.length - 1; _o168 >= 0; _o168--) {
          this._datatype[_o168].type && -1 != this._datatype[_o168].type.indexOf(l[t]) && -1 == n.indexOf(this._datatype[_o168]) && n.push(this._datatype[_o168]);
        }
      } else {
        for (var _o169 = 0; _o169 < this._datatype.length; _o169++) {
          this._datatype[_o169].type && -1 != this._datatype[_o169].type.indexOf(l[t]) && -1 == n.indexOf(this._datatype[_o169]) && n.push(this._datatype[_o169]);
        }
      }
      return n;
    }
  }]);
}($2BaseConfigContainer.BaseConfigContainer);